404 error page automatic search

Has anyone set up an error 404 page that automatically returns a list of search entries for the file that is missing? For instance, if I moved a file from one album to another, it would be nice if when they clicked on the link from a search engine it brought them up to my error page and showed the file in the new location, since the file name itself did not change, just the location.

Thanks!

Comments

  • acrylian Administrator, Developer
    Zenphoto does not store records about what has been moved where.

    Also, if you moved an image to another album it is "another" image to Zenphoto as you can have several images with the same file name in different albums as well as subalbums of the same folder name within several albums.
  • Ok, I'm not sure if you follow what I want to do.

    Let's say they were looking for the file "bookmarks/mybookmark.jpg" and it has moved to "bookmarks/English/mybookmark.jpg" I don't need Zenphoto to know it moved, I just need to make it easy to display search results for "mybookmark.jpg" and let Zenphoto search by filename and show the relevant result(s). It doesn't matter where it moved-- it can search for it anyway. I am assuming I could fairly easily retrieve the name that it was looking for because at least the missing album is outputted on the 404 page, so I could probably create a "click here to search for the missing file" link that would link to a search page?

    My question is, has anyone already done something like this (so I don't have to reinvent the wheel) or perhaps even incorporated an automatic search results built in to the 404 page? Having the thumbnail automatically appear would prevent people leaving my page after not finding what they wanted right away.

    Thanks.
  • acrylian Administrator, Developer
    Indeed I missunderstood.

    What you want is probably possible as you describe it. Probably also setting up a search automatically using the not found info. As far as I know no one ever tried (at least has not told so).

    I suggest to look at the search class documentation on the functions guide.
  • I have something like this setup on my site. I haven't looked at automatically showing search results, but I do have it generate links for them to click for search.

    For instance:
    This used to be an album, but when I restructured my directories I needed a way to provide an easy to find navigation for search.

    A link to an image and folder that were both moved with search links for both the album and object itself.

    Below is the coding I'm using on my 404 page, so I'm sure you can modify it to auto-search if you want, I just never took it that far. It's probably not pretty, or efficient, but it does the job for the most part.
    `


    <?php
    echo gettext("I'm sorry, the link you clicked appears to lead to something that has been moved, is temporarily offline, is missing, or is broken.");
    ?>

    Please click any of the links below (if any) to search for any realtive pages:
    <?php
    if (isset($album)) {
    echo '<br />image'.FULLWEBPATH.getSearchURL($album, NULL, NULL, NULL).'';
    }
    if (isset($image)) {
    echo '
    image'.FULLWEBPATH.getSearchURL($image, NULL, NULL, NULL).'';
    }
    if (isset($obj)) {
    echo '
    image'.FULLWEBPATH.getSearchURL(substr(basename($obj),0,-4), NULL, NULL, NULL).'';
    }
    ?>


    `
  • Thank you micheall!! Adding your code is a big improvement to my site.

    (Note that you may want to correct the spelling of "relative" in your code above.)

    Nathan
  • Ahaha, I didn't even notice the typo, thanks!

    Edit:
    Also, let me know if you take it a step further to auto-display search results. I would be interested to see that in action.
  • I worked on trying to get image search results to show but I don't know enough of what's going on in the code to make it work. I can get it to show the proper search word but I don't think the find functions are looking in the proper places...

    If someone knows an easy way to simply redirect to the search page and show results for the required file that would maybe work for me also... otherwise what I have now is sufficient. I suppose I could use javascript on the 404 page to redirect with a little message like "file not found... searching in 3 seconds" etc.
  • acrylian noted in another post that
    "You can call Zenpage pages on any other page using the object model. So create a Zenpage page and keep it unpublished to call it on the search page."
    So perhaps there would be a way to reference the search page too...? No time to look into it now though.
  • acrylian Administrator, Developer
    The search page is a custom page (see the theming tutorial) that is outside the management. The Zenpage page reference I made above was for an easy to manage way of a multilingual description on that page.

    For search options look at the search class and the related template functions.
Sign In or Register to comment.